package com.tongbo.mobilesafe.ui;

import com.tongbo.mobilesafe.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SetupGuide3Activity extends Activity implements OnClickListener{
	private Button bt_next;
	private Button bt_pre;
	private Button bt_select_contact;
	private EditText et_number;
	private SharedPreferences sp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setupguide3);
		sp = getSharedPreferences("config", Context.MODE_PRIVATE);
		bt_next = (Button) this.findViewById(R.id.bt_next);
		bt_pre = (Button) this.findViewById(R.id.bt_previous);
		bt_select_contact = (Button) this.findViewById(R.id.bt_select_contact);
		bt_next.setOnClickListener(this);
		bt_pre.setOnClickListener(this);
		bt_select_contact.setOnClickListener(this);
		et_number = (EditText) this.findViewById(R.id.et_setup3_number);
		
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bt_select_contact:
			Intent intent = new Intent(this, SelectContactActivity.class);
			//激活一个带返回值的界面
			startActivityForResult(intent, 0);
			
			break;
		case R.id.bt_next:
			String number = et_number.getText().toString().trim();
			if("".equals(number)){
				Toast.makeText(getApplicationContext(), "安全号码不能为空", 0).show();
				return;
			}else{
				Editor editor = sp.edit();
				editor.putString("safenumber", number);
				editor.commit();
			}
			Intent intent4 = new Intent(this, SetupGuide4Activity.class);
			//设置完成之后，一定要把当前的activity从当前任务栈中移除
			finish();
			startActivity(intent4);
			//设置activity切换之后的动画效果
			overridePendingTransition(R.anim.translate_in, R.anim.translate_out);
			break;
		case R.id.bt_previous:
			Intent intent2 = new Intent(this, SetupGuide2Activity.class);
			//设置完成之后，一定要把当前的activity从当前任务栈中移除
			finish();
			startActivity(intent2);
			//设置activity切换之后的动画效果
			overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
			break;
		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
		super.onActivityResult(requestCode, resultCode, intent);
		if(null!=intent){
			String number = intent.getStringExtra("number");
			et_number.setText(number);
		}
	}
}